package com.lu.log

import android.text.TextUtils
import com.lu.log.printer.DefaultLogPrinter


/**
 *author: luqihua
 *date:2020/3/27
 *description: 本地log的包装类
 **/
object LocalLog : LogBuilder() {

    @JvmStatic
    fun configure(config: LogBuilder.() -> Unit) {
        this.apply(config)
    }

    private fun getTag(tag: String): String {
        return if (!TextUtils.isEmpty(prefix)) {
            "$prefix-$tag"
        } else {
            tag
        }
    }

    @JvmStatic
    fun d(tag: String, message: String) {
        printers.forEach { it.d(getTag(tag), message) }
    }

    @JvmStatic
    fun i(tag: String, message: String) {
        printers.forEach { it.i(getTag(tag), message) }
    }

    @JvmStatic
    fun w(tag: String, message: String, error: Throwable? = null) {
        printers.forEach { it.w(getTag(tag), message, error) }
    }

    @JvmStatic
    fun e(tag: String, message: String, error: Throwable? = null) {
        printers.forEach { it.e(getTag(tag), message, error) }
    }
}

open class LogBuilder(
    var prefix: String = "",
    var printers: List<ILogPrinter> = listOf(DefaultLogPrinter)
)




